<template>
  <router-view/>

  <transition name="fade" mode="out-in">
    <div class="loading_wrapper" v-show="loadingShow">
      <van-loading class="loading_box" type="spinner" vertical size="50px">
        <span style="font-size: 16px">{{ $t('data_loading') }}</span>
      </van-loading>
    </div>
  </transition>

</template>

<script>
import {computed, onMounte, onMounted, ref, watch} from 'vue'
import {useI18n,} from 'vue-i18n'
import {useRoute, onBeforeRouteLeave} from 'vue-router'
import {useStore} from "vuex";
import MobileDetect from "mobile-detect";
import {uploadDeviceInfo} from "@/api/home";

export default {
  setup() {
    const {locale} = useI18n()
    const fadeName = ref(null)
    const routes = useRoute()
    const store = useStore()
    const loadingShow = computed(() => {
      return store.getters.getViewLoading
    })
    watch(() => routes.path, (value) => {
      store.dispatch('changeLoading', true)
    })
    const getCaption = (name) => {
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
      var r = window.location.search.substr(1).match(reg);
      if (r != null) return unescape(r[2]);
      return '';
    }
    const productName = getCaption('productName')
    const channel = getCaption('channel')
    const localeName = getCaption('locale')
    if (productName) {
      localStorage.setItem('productName', productName)
    }
    if (channel) {
      localStorage.setItem('channel', channel)
    }
    if (localeName) {
      localStorage.setItem('locale', localeName)
      locale.value = localeName
    }
    return {
      loadingShow,
      fadeName
    }
  }
}
</script>

<style lang="less">
.fade-enter-active, .fade-leave-active {
  transition: opacity .3s;
}

.fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
  opacity: 0;
}

#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
  min-height: 100%;
  min-width: 100%;
  background-color: #f2f3f5;
  z-index: -1;
}

body {
  height: 100vh;
  min-width: 100%;
  padding: 0;
  margin: 0;
}

.loading_wrapper {
  position: absolute;
  background-color: #FFFFFF;
  width: 100%;
  height: 100%;
  z-index: 1899;

  .loading_box {
    margin-top: 200px;
  }
}

.money_symbol {
  font-size: 16px;
  margin-right: 3px;
}

.symbol {
  font-size: 16px;
  line-height: 20px;
  display: inline-block;
  transform: translateY(4px);
  margin-right: 2px;
}

.confirm {
  margin-top: 20px;
  text-align: center;

  button {
    width: 300px;
    padding: 10px 0;
    color: #ffffff;
    border: none;
    font-size: 16px;
    background: linear-gradient(-45deg, #FF5252, #FF8C3C);
    box-shadow: 0px 4px 10px 0px rgba(255, 92, 78, 0.52);
    border-radius: 29px;
  }

}

.loading_wrapper {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.van-picker__confirm {
  color: #FF5252 !important;
}

/*向左滑动*/
@keyframes slideInLeft {
  0% {
    transform: translateX(100%);
  }
  100% {
    transform: translateX(0);
  }
}

@keyframes slideInRight {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(100%);
  }
}

.slide-left-enter-active {
  animation: slideInLeft .3s linear forwards;
}

.slide-left-leave-active {
  animation: slideOutLeft .3s linear forwards;
}

/*向右滑动*/
@keyframes slideOutLeft {
  0% {
    transform: translateX(100%);
  }
  100% {
    transform: translateX(0);
  }
}

@keyframes slideOutRight {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(100%);
  }
}

.slide-right-enter-active {
  animation: slideInRight .3s linear forwards;
}

.slide-right-leave-active {
  animation: slideOutRight .3s linear forwards;
}
</style>
